package fr.univ.lille1.server.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="SESSION_KEY")
public class SessionKey implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 806508594200409133L;
	
	@Id
	@OneToOne
	@JoinColumn(nullable=false)
	private User user;
	
	@Column
	private String sessionKey;
	
	@Column
	private long generateTime;
	
	public SessionKey (User u, String key,long generateTime){
		super();
		this.user=u;
		this.sessionKey=key;
		this.generateTime=generateTime;
	}
	
	public SessionKey (){
		super();
	}
	
	public User getUser(){
		return this.user;
	}
	
	public String getSessionKey(){
		return this.sessionKey;
	}

	public void setUser(User u){
		this.user=u;
	}
	
	public void setSessionKey(String key){
		this.sessionKey=key;
	}
	
	public long getGenerateTime(){
		return this.generateTime;
	}
	
	public void setGenerateTime(long generateTime){
		this.generateTime=generateTime;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		SessionKey other = (SessionKey) obj;
		if (user == null) {
			if (other.user != null){
				return false;
			}
		} else if (!user.equals(other.user)){
			return false;
		}
		return true;
	}	
}
